<template>
    <div class="count">
        <div class="topTit f f-a-c f-j-b">
            <div class="left f f-a-c">
                <img src="/src/status/logo.png" class="logo" alt="">
                <span>H.S.国际问题研究平台</span>
            </div>
            <div class="right">
                <img @click="setting" src="/src/status/img/cha.png" class="myStat" alt="">
            </div>
        </div>
        <div class="body">
            <div class="title">
                {{ objs.title }}
            </div>
            <div class="time f f-a-c">
                <div class="tim">{{ objs.date }} {{ objs.time }}</div>
                <!-- <div class="name">新闻来源：中国日报</div> -->
            </div>
            <div class="content" v-html="objs.content"></div>
            <!-- /下面的箭头 -->
            <div class="botBtn f f-a-c f-j-c">
                <img v-if="false" src="/src/status/jiantou/zuo.png" class="zuo" alt="">
                <div v-if="true" class="center f f-a-c">
                    <div v-if="objs.is_collect == 2" class="cenLef f f-a-c f-j-c" @click="Ingredients"><img
                            src="/src/status/jiantou/dk.png" class="dk" alt="">采集</div>
                    <div v-if="objs.is_collect == 1" style="color: #32BBEA;" class="cenLef f f-a-c f-j-c"><img src="/src/status/img/yicaiji.png"
                            class="dk"  alt="">已采集</div>
                    <div @click="transl" class="cenRig f f-a-c f-j-c"><img src="/src/status/jiantou/zidian.png" class="dk"
                            alt="">翻译</div>
                </div>
                <img v-if="false" src="/src/status/jiantou/you.png" class="zuo" alt="">
            </div>
        </div>
    </div>
</template>

<script setup>
import { configProviderContextKey } from 'element-plus';
import router from '../../router';
import { ref, onMounted } from 'vue';
import { CollectData, Translate } from '../../api/index';
import { showLoadingToast, closeToast, showToast, showConfirmDialog, Toast } from 'vant'
let count = ref('<div>45464866</div>')
const emit = defineEmits(['detilStua', 'caijiSeting'])
let id = ref(1)
let num = ref(1)
let objs = ref({})
// let obj = ref({})

// onMounted(() => {
//     obj.value = localStorage.getItem('objItem')
//     console.log(obj.value, '123456789');
// })
// ==============================================================================
// 组件传值
const props = defineProps({
    obj: {
        default: {},
        type: Object,
    },
    title: {
        default: {},
        type: Object,
    },
});
onMounted(() => {
    objs.value = props.obj
    console.log(props.title, '123456');
})
// /点击翻译
const transl = async () => {
    const toast = showLoadingToast({
        duration: 0,
        forbidClick: true,
        message: '翻译中...',
    });
    let n = await Translate({
        title: props.obj.title,
        content: props.obj.content,
    })
    closeToast();
    showToast(n.msg)
    objs.value.title = n.content.data.zh_title
    objs.value.content = n.content.data.zh_content
}
// 点击采集
const Ingredients = async () => {
    const toast = showLoadingToast({
        duration: 0,
        forbidClick: true,
        message: '采集中...',
    });
    let n = await CollectData({
        topics_id: props.title.id,
        uri: props.obj.uri,
        title: props.obj.title,
        content: props.obj.content,
        article_time: props.obj.date + ' ' + props.obj.time,
    })
    closeToast();
    showToast(n.msg)
    if (n.code == 200) {
        emit('caijiSeting')
    }
}
// 向父组件传函数
const setting = () => {
    emit('detilStua')
}
// 子传父

// 这是页面刚打开时候
// /组件卸载后
// 返回首页
</script>
<style lang="scss" scoped>
@function pxfn($px) {
    @return calc($px / 3.75) * 1vw;
}

.title {
    font-size: pxfn(20);
    font-family: PingFang SC, PingFang SC-600;
    font-weight: 600;
    text-align: LEFT;
    color: #1d2129;
    text-indent: 2em;
}

.time {
    margin: pxfn(15) 0;
    font-size: pxfn(12);
    font-family: PingFang SC, PingFang SC-400;
    font-weight: 400;
    // text-align: LEFT;
    color: #868d9c;

    .tim {
        margin-right: pxfn(15);
    }
}

.body {
    height: calc(100vh - pxfn(48));
    padding: pxfn(15);
    overflow-y: auto;
    padding-bottom: pxfn(68);

    .botBtn {
        position: fixed;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 100%;
        background-color: #fff;
        height: pxfn(68);
        padding: 0 pxfn(15);

        .center {
            margin: 0 pxfn(40);
        }

        .cenLef {
            width: pxfn(78);
            height: pxfn(38);
            border-radius: pxfn(8);
            font-size: pxfn(14);
            font-family: PingFang SC, PingFang SC-400;
            font-weight: 400;
            text-align: center;
            color: #1d2129;
            margin-right: pxfn(6);
        }

        .cenRig {
            width: pxfn(78);
            height: pxfn(38);
            background: #f7f8fa;
            border-radius: pxfn(8);
            font-size: pxfn(14);
            font-family: PingFang SC, PingFang SC-400;
            font-weight: 400;
            text-align: center;
            color: #1d2129;
        }

        .dk {
            width: pxfn(21);
            height: pxfn(20);
            margin-right: pxfn(4);
        }

        .zuo {
            width: pxfn(44);
            height: pxfn(44);
        }
    }
}



.count {
    position: fixed;
    top: 0;
    z-index: 999;
    width: 100vw;
    height: 100vh;
    background-color: #fff;
    padding-top: pxfn(50);
}

.topTit {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: pxfn(48);
    border: 1px solid #edf3fa;
    padding: pxfn(15);
    z-index: 1;
    font-size: pxfn(14);
    font-weight: 600;

    .logo {
        width: pxfn(27);
        height: pxfn(24);
        margin-right: pxfn(10);
    }

    .myStat {
        width: pxfn(24);
        height: pxfn(24);
    }
}

.content {
    text-indent: 2em;
    line-height: 2;
    font-size: pxfn(14);
}
</style>